package cn.easy.jacob.rocketmq;

import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.consumer.MQPushConsumer;
import org.apache.rocketmq.client.exception.MQClientException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

public class RocketMQManager {
    private final Logger LOGGER = LoggerFactory.getLogger(MQPushConsumer.class);

    public RocketMQManager(DefaultMQPushConsumer mqConsumer, List<MessageListener> messageListeners, String topic, String tag) {
        try {
            mqConsumer.subscribe(topic, tag);
            messageListeners.forEach(messageListener -> mqConsumer.registerMessageListener(messageListener));
            mqConsumer.start();
            LOGGER.info("消息接收者启动");
        } catch (MQClientException e) {
            LOGGER.error("MQ：启动生产者失败：{}-{}", e.getResponseCode(), e.getErrorMessage());
            e.printStackTrace();
        }
    }
}